package com.gupaoedu.vip.prototype;

import java.io.*;
import java.util.Date;

/**
 * Created by zhaozhonghai on 2017/5/24.
 */
public class MingRen implements Cloneable,Serializable {


    private static final long serialVersionUID = 3313508321190667689L;

    private JiuWei jiuWei;
    private String name;
    private int age;
    protected Date birthday;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    //影分身
    public MingRen yinfenshen(){
        MingRen cope=null;
        //一般复制
//        try {
//            cope=(MingRen)this.clone();
//        } catch (CloneNotSupportedException e) {
//            e.printStackTrace();
//        }
        //深处复制
        ObjectOutputStream oos=null;
        ByteArrayOutputStream bos = null;
        ObjectInputStream ois=null;
        ByteArrayInputStream bis=null;
        try {
            bos=new ByteArrayOutputStream();
            oos=new ObjectOutputStream(bos);
            oos.writeObject(this);
            oos.flush();
            bis=new ByteArrayInputStream(bos.toByteArray());
            ois=new ObjectInputStream(bis);
            cope=(MingRen) ois.readObject();
            cope.setBirthday(new Date());
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                bos.close();
                oos.close();
                bis.close();
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return cope;
    }



    public JiuWei getJiuWei() {
        return jiuWei;
    }

    public void setJiuWei(JiuWei jiuWei) {
        this.jiuWei = jiuWei;
    }
}
